package com.sckj.springboot.controller;

import com.sckj.springboot.entity.JsonResult;
import com.sckj.springboot.exception.BusinessErrorException;
import com.sckj.springboot.exception.BusinessMsgEnum;
import com.sckj.springboot.exception.GlobalExceptionHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/exception")
public class ExceptionController {
    //打印日志
    private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @PostMapping("/test")
    public JsonResult test(@RequestParam("name") String name , @RequestParam("pass") String pass){
        logger.info("name: {}",name);
        logger.info("pass: {}",pass);
        return new JsonResult();
    }

    @GetMapping("/null/point/excception")
    public JsonResult testNullPiontException(){
        String str = null;
        str.length();
        return new JsonResult();
    }

    /**
     * 全局自定义异常
     */
    @GetMapping("/busniess")
    public JsonResult testException(){
        try{

            int i=1/0;
        }catch (Exception ex){
            throw new BusinessErrorException(BusinessMsgEnum.UNEXPECTED_EXCEPTION);
        }
        return new JsonResult();
    }

}
